#' <Add Title>
#'
#' <Add Description>
#'
#' @param data
#' @param r 半径
#' @param up 颜色
#' @param down 颜色
#' @param notsig 颜色
#' @param xAxisLabel1 X轴标签
#' @param yAxisLabel1 Y轴标签
#' @param xLabelSize 字体大小
#' @param yLabelSize
#' @param xLabelplot 字体位置
#' @param yLabelplot
#' @param xLabelFamily 字体样式
#' @param yLabelFamily
#' @param xLabelWidth 字体粗细 0:不加粗;bold:加粗
#' @param yLabelWidth
#' @param titlePosition 大标题位置 0:left ; 1:middle; 2:right
#' @param titleSize 大标题字体大小
#' @param titleFamily 大标题字体粗细
#' @param titleWidth 大标题
#' @param titleText 字体大小
#' @param xFontSize
#' @param yFontSize
#' @param yFontWeight 字体宽度
#' @param xFontWeight
#' @param xScaleNumber 刻度个数 5:小于10 ; 10: 大于10
#' @param yScaleNumber
#' @param xangle 刻度旋转角度
#' @param yangle
#' @param yfonttop 刻度距离轴的距离
#' @param xfonttop
#' @param fc
#' @param pvalue
#' @param gridline 0: 无网格; 1: 有网格
#' @param legendSize
#' @param legendheight
#' @param legendwidth
#' @param legendPosition 0:右方; 1: 下方; 2: 左方; 3: 上方
#' @param legendFamily
#' @param allFontFamily
#' @param shape
#' @param shapeRound
#' @param infoFamily
#' @param infoSize
#' @param width 暂时弃用
#' @param height 暂时弃用
#' @param elementId
#'
#' @import htmlwidgets
#' @export
volcanoD3 <- function(data,
                      r = 3, #半径
                      up = "#ff5050",  #  颜色
                      down = "#26d25d",  #  颜色
                      notsig = "rgb(101 179 254)",  #  颜色


                      xAxisLabel1 = 'Log[2]FC', # X轴标签
                      yAxisLabel1 = '-Log[10]PValue', # Y轴标签
                      xLabelSize = '18px',  # 字体大小
                      yLabelSize = '18px',
                      xLabelplot = 'middle', # 字体位置
                      yLabelplot = 'middle',
                      xLabelFamily = 'Arial',  # 字体样式
                      yLabelFamily = 'Arial',
                      xLabelWidth = '0', # 字体粗细 0:不加粗,bold:加粗
                      yLabelWidth = '0',


                      titlePosition = "0", # 大标题位置 0:left , 1:middle, 2:right
                      titleSize = "16px", # 大标题字体大小
                      titleFamily = "Arial", # 大标题字体样式
                      titleWidth = "0", # 大标题字体粗细
                      titleText = "VolcanoPlot", # 大标题


                      xFontSize = '14px', # 字体大小
                      yFontSize = '14px',
                      yFontWeight = '0',  # 字体宽度
                      xFontWeight = '0',
                      xScaleNumber = '5',  # 刻度个数 5:小于10 , 10: 大于10
                      yScaleNumber = '5',
                      xangle = 0,  # 刻度旋转角度
                      yangle = 0,
                      yfonttop = 5, # 刻度距离轴的距离
                      xfonttop = 5,

                      fc = '1.5',
                      pvalue = '0.05',

                      gridline = "0", #0: 无网格, 1: 有网格
                      legendSize = '16px',
                      legendheight = 10,
                      legendwidth = 30,
                      legendPosition = "0", #0:右方, 1: 下方, 2: 左方, 3: 上方
                      legendFamily = "Arial",

                      allFontFamily = "Arial",

                      shape = "circle",
                      shapeRound = 4,

                      infoFamily = "Arial",
                      infoSize = "16px",
                      myWidth = 500,
                      myHeight = 500,

                      width = NULL, height = NULL, elementId = NULL) {

  # forward options using x
  x = list(
    data=data,
    r = r,
    up = up,
    down = down,
    notsig = notsig,


    xAxisLabel1 = xAxisLabel1,
    yAxisLabel1 = yAxisLabel1,
    xLabelSize = xLabelSize,
    yLabelSize = yLabelSize,
    xLabelplot = xLabelplot,
    yLabelplot = yLabelplot,
    xLabelFamily = xLabelFamily,
    yLabelFamily = yLabelFamily,
    xLabelWidth = xLabelWidth,
    yLabelWidth = yLabelWidth,


    titlePosition = titlePosition,
    titleSize = titleSize,
    titleFamily = titleFamily,
    titleWidth = titleWidth,
    titleText = titleText,


    xFontSize = xFontSize,
    yFontSize = yFontSize,
    yFontWeight = yFontWeight,
    xFontWeight = xFontWeight,
    xScaleNumber = xScaleNumber,
    yScaleNumber = yScaleNumber,
    xangle = xangle,
    yangle = yangle,
    yfonttop = yfonttop,
    xfonttop = xfonttop,

    fc = fc,
    pvalue = pvalue,

    gridline = gridline,
    legendSize = legendSize,
    legendheight = legendheight,
    legendwidth = legendwidth,
    legendPosition = legendPosition,
    legendFamily = legendFamily,

    allFontFamily = allFontFamily,

    shape = shape,
    shapeRound = shapeRound,

    infoFamily = infoFamily,
    infoSize = infoSize,
    myWidth = myWidth,
    myHeight = myHeight

  )

  # create widget
  htmlwidgets::createWidget(
    name = 'volcanoD3',
    x,
    width = width,
    height = height,
    package = 'D3Widget',
    elementId = elementId
  )
}

#' Shiny bindings for volcanoD3
#'
#' Output and render functions for using volcanoD3 within Shiny
#' applications and interactive Rmd documents.
#'
#' @param outputId output variable to read from
#' @param width,height Must be a valid CSS unit (like \code{'100\%'},
#'   \code{'400px'}, \code{'auto'}) or a number, which will be coerced to a
#'   string and have \code{'px'} appended.
#' @param expr An expression that generates a volcanoD3
#' @param env The environment in which to evaluate \code{expr}.
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
#'   is useful if you want to save an expression in a variable.
#'
#' @name volcanoD3-shiny
#'
#' @export
volcanoD3Output <- function(outputId, width = '100%', height = '400px'){
  htmlwidgets::shinyWidgetOutput(outputId, 'volcanoD3', width, height, package = 'D3Widget')
}

#' @rdname volcanoD3-shiny
#' @export
renderVolcanoD3 <- function(expr, env = parent.frame(), quoted = FALSE) {
  if (!quoted) { expr <- substitute(expr) } # force quoted
  htmlwidgets::shinyRenderWidget(expr, volcanoD3Output, env, quoted = TRUE)
}
